package com.ruoyi.web.controller.baodao.service;

import com.ruoyi.baodao.entity.MFGoods9999;
import com.ruoyi.baodao.entity.MFGoodsLink;
import com.ruoyi.baodao.entity.MFGoodsLinkExample;
import com.ruoyi.baodao.mapper.MFGoodsLinkMapper;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GoodsLinksService {
    @Autowired
    MFGoodsLinkMapper mfGoodsLinkMapper;

    @Transactional
    public int insert(MFGoodsLink mfGoodsLink){

        // 查询数据库中是否有此数据
        MFGoodsLinkExample mfGoodsLinkExample = new MFGoodsLinkExample();
        MFGoodsLinkExample.Criteria criteria = mfGoodsLinkExample.createCriteria();
        criteria.andShopidEqualTo(mfGoodsLink.getShopid());
        criteria.andGoodscodeEqualTo(mfGoodsLink.getGoodscode());
        criteria.andLinkgoodscodeEqualTo(mfGoodsLink.getLinkgoodscode());
        List<MFGoodsLink> result =  mfGoodsLinkMapper.selectByExample(mfGoodsLinkExample);
        if(result == null || result.size() <=0){
           return mfGoodsLinkMapper.insert(mfGoodsLink);
        }
            return 0;
        }
}
